package com.kzd.btgame.main.money.adapter

import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.kzd.btgame.R
import com.kzd.btgame.entity.*
import com.kzd.btgame.main.toGameDetailsActivity
import com.module.lemlin.image.loadImage
import com.module.lemlin.image.loadCircleImage


class MoneySignTagAdapter :
    BaseQuickAdapter<SignConfig, BaseViewHolder>(R.layout.item_money_sign_tag) {
    override fun convert(holder: BaseViewHolder, item: SignConfig) {
        holder.setText(
            R.id.tvMoneySignTagName,
            if (item.status == 0) StringBuilder().append("+").append(item.points) else "已领"
        )
            .getView<ImageView>(R.id.ivMoneySignTagIcon).apply {
                setImageResource(if (item.status == 0) R.mipmap.ic_30016 else R.mipmap.ic_30015)
            }
    }
}

class MoneySignDayAdapter :
    BaseQuickAdapter<SignConfig, BaseViewHolder>(R.layout.item_money_sign_day) {
    override fun convert(holder: BaseViewHolder, item: SignConfig) {
        holder.setText(
            R.id.tvMoneySignDayName,
            StringBuilder().append(item.day).append("天")
        )
    }
}

class MoneyTaskNewAdapter :
    BaseQuickAdapter<MoneyTask, BaseViewHolder>(R.layout.item_money_task_new) {
    init {
        addChildClickViewIds(R.id.tvMoneyTaskNewSubmit)
    }

    override fun convert(holder: BaseViewHolder, item: MoneyTask) {
        holder.setText(R.id.tvMoneyTaskNewName, item.title)
            .setText(
                R.id.tvMoneyTaskNewCount, StringBuilder().append("（+")
                    .append(item.points).append("积分）")
            )
            .setText(
                R.id.tvMoneyTaskNewSubmit, when (item.verify_rs) {
                    0 -> "去完成"
                    1 -> "领取"
                    else -> "已领取"
                }
            )
    }
}

class MoneyTaskDayAdapter :
    BaseQuickAdapter<MoneyTaskList, BaseViewHolder>(R.layout.item_money_task_day) {
    override fun convert(holder: BaseViewHolder, item: MoneyTaskList) {
        holder.setText(R.id.tvMoneyTaskDayName, item.name)
            .setText(R.id.tvMoneyTaskDaySub, item.title)
            .getView<ImageView>(R.id.ivMoneyTaskDayIcon)
            .loadImage(item.icon)
    }
}

class MoneyTaskListAdapter :
    BaseQuickAdapter<MoneyTask, BaseViewHolder>(R.layout.item_money_task_list) {
    init {
        addChildClickViewIds(R.id.tvMoneyTaskListGo)
    }

    override fun convert(holder: BaseViewHolder, item: MoneyTask) {
        holder.setText(R.id.tvMoneyTaskListName, item.name)
            .setText(
                R.id.tvMoneyTaskListPoints,
                StringBuilder().append("+").append(item.points).append("积分")
            )
            .setText(R.id.tvMoneyTaskListSub, item.title)
            .setText(
                R.id.tvMoneyTaskListGo, when (item.verify_rs) {
                    0 -> "去完成"
                    1 -> "领取"
                    else -> "已领取"
                }
            )
            .getView<ImageView>(R.id.ivMoneyTaskListIcon)
            .loadImage(item.icon)
    }
}

class MoneyTaskPlayAdapter :
    BaseQuickAdapter<MoneyTaskPlay, BaseViewHolder>(R.layout.item_money_task_play) {
    init {
        addChildClickViewIds(R.id.tvMoneyTaskPlayGo)
        setOnItemClickListener { _, _, position ->
            val itemData = getItem(position)
            toGameDetailsActivity(itemData.gid)
        }
    }

    override fun convert(holder: BaseViewHolder, item: MoneyTaskPlay) {
        holder.setText(R.id.tvMoneyTaskPlayName, item.name)
            .setText(R.id.tvMoneyTaskPlaySub, item.content)
            .setText(
                R.id.tvMoneyTaskPlayGo, when (item.status) {
                    1 -> "进行中"
                    2 -> "领取"
                    3 -> "已完成"
                    4 -> "未开始"
                    5 -> "已结束"
                    -1 -> "名额已满"
                    else -> "报名"
                }
            )
            .getView<ImageView>(R.id.ivMoneyTaskPlayIcon)
            .loadImage(item.icon)
    }
}

class MoneyTaskMallAdapter :
    BaseQuickAdapter<MoneyTaskMall, BaseViewHolder>(R.layout.item_money_task_mall) {
    override fun convert(holder: BaseViewHolder, item: MoneyTaskMall) {
        holder.setText(R.id.tvMoneyTaskMallName, item.goods_name)
            .setText(R.id.tvMoneyTaskMallPoint, StringBuilder(item.market_price).append("积分"))
            .getView<ImageView>(R.id.ivMoneyTaskMallIcon)
            .loadImage(item.goods_thumb)
    }
}

class MoneyBossSharedAdapter :
    BaseQuickAdapter<MoneyBossShared, BaseViewHolder>(R.layout.item_money_boss_shared) {

    init {
        addChildClickViewIds(R.id.tvMoneyBossSharedSubmit)
    }

    override fun convert(holder: BaseViewHolder, item: MoneyBossShared) {
        holder.setText(R.id.tvMoneyBossSharedName, item.name)
            .setText(
                R.id.tvMoneyBossSharedDesc,
                StringBuilder().append("充值").append(item.money).append("元好友得")
                    .append(item.send_money).append("元")
            )
            .setText(R.id.tvMoneyBossSharedTime, item.show_time)
            .getView<ImageView>(R.id.ivMoneyBossSharedIcon)
            .loadImage(item.icon)
    }
}

class MoneyBossInviteAdapter :
    BaseQuickAdapter<MoneyBossInvite, BaseViewHolder>(R.layout.item_money_boss_invite) {
    override fun convert(holder: BaseViewHolder, item: MoneyBossInvite) {
        holder.setText(R.id.tvMoneyBossInviteUserName, item.user_name)
            .setText(R.id.tvMoneyBossInviteName, item.invite_name)
            .setText(R.id.tvMoneyBossInviteCoin, StringBuilder().append("+").append(item.coin))
            .getView<ImageView>(R.id.ivMoneyBossInviteIcon).apply {
                loadCircleImage(item.icon, error = R.mipmap.ic_test_1)
            }
    }
}

class MoneyExperienceAdapter :
    BaseQuickAdapter<MoneyExperience, BaseViewHolder>(R.layout.item_money_experience) {
    override fun convert(holder: BaseViewHolder, item: MoneyExperience) {
        holder.setText(R.id.tvMoneyExperienceGameName, item.gameName)
            .setText(R.id.tvMoneyExperienceCoin, item.bind_coin)
    }
}